import {
	Viewer
} from 'cesium'

import ProvinceBlock from './ProvinceBlock'
import CountryRange from './CountryRange'
import Baseplate from './Baseplate'
import ProvinceView from '../ProvinceView'

class CountryView {
	
	viewer: Viewer | null = null
	isLoad: boolean = false
	isGrowing: boolean = false
	
	provinceBlock: ProvinceBlock | null = null
	countryRange: CountryRange | null = null
	baseplate: Baseplate | null = null
	provinceView: ProvinceView | null = null
	
	
	constructor(viewer: Viewer, provinceView: ProvinceView) {
		this.viewer = viewer
		
		this.provinceView = provinceView
		this.provinceBlock = new ProvinceBlock(viewer, provinceView)
		this.countryRange = new CountryRange(viewer)
		this.baseplate = new Baseplate(viewer)
	}
	
	async load() {
		if(this.isGrowing) return
		this.isGrowing = true
		
		if(this.isLoad) this.unload()
		this.isLoad = true
		
		await Promise.all([
			this.provinceBlock.load(),
			this.countryRange.load(),
			this.baseplate.load()
		])

		this.isGrowing = false
	}
	
	async unload(){
		if(this.isGrowing) return
		this.isGrowing = true
		
		if(this.isLoad == false) return
		this.isLoad = false
		
	    this.provinceBlock.unload(),
		this.countryRange.unload(),
		this.baseplate.unload()

		this.isGrowing = false
	}
	
	async show() {
		if(this.isGrowing) return
		this.isGrowing = true
		
		await Promise.all([
			this.provinceBlock.show(),
			this.countryRange.show(),
			this.provinceBlock.show(),
			this.baseplate.show()
		])
		
		this.isGrowing = false
	}
	
	async hide() {
		if(this.isGrowing) return
		this.isGrowing = true
		
		await Promise.all([
			this.provinceBlock.hide(),
			this.countryRange.hide(),
			this.provinceBlock.hide(),
			this.baseplate.hide()
		])
		
		this.isGrowing = false
	}
}
export default CountryView